#ifndef FPLAYER_CAPTURE_H
#define FPLAYER_CAPTURE_H

#include "MediaDefine.h"
#include "Device.h"
#include "concurrent/HandlerThread.h"

//枚举 消息ID
enum MsgIDCapture {
  MsgIDCapture_Start = MsgID_None,
  MsgIDCapture_Stop,
};

class ICapture;
class IRender;

//类
class IFrameCallback {
public:
  IFrameCallback() = default;

  virtual ~IFrameCallback() = default;

  /**
   * YUV、PCM原始流的的传输
   * @param pCapture 采集对象
   * @param pMediaFrame YUV、PCM数据
   */
  virtual void onFrameCallback(ICapture *pCapture, MediaFrame *pMediaFrame) = 0;
};

/**
 * author: x-fan
 * date: 2024/1/9
 * desc: 采集定义
 */
class ICapture : public HandlerThread {
protected:
  //设备
  IDevice *_pDevice = nullptr;

  IFrameCallback *_pFrameCallback = nullptr;

public:

  explicit ICapture(IDevice *pCapDev) : _pDevice(pCapDev) {

  };

  virtual ~ICapture() noexcept = default;

  /**
   * 启动设备开始采集
   */
  virtual void startCapture() = 0;

  /**
   * 关闭设备停止采集
   */
  virtual void stopCapture() = 0;

  /**
   * 视频采集、音频采集或者音视频采集
   * @return MediaType_Video、MediaType_Audio、(MediaType_Video|MediaType_Audio)
   */
  virtual int32_t capacity() = 0;

  void handleMessage(Message *pMsg) override;

  void toString() override;

  void registerFrameCallback(IFrameCallback *pFrameCallback);

  void unregisterFrameCallback();

};


/************************* 采集对象管理 *************************/
#ifdef __cplusplus
extern "C" {
#endif

/**
 * 创建采集对象
 * @param pDevice 设备
 * @return 采集对象
 */
ICapture *Capture_Create(IDevice *pDevice);

/**
 * 采集对象释放资源
 */
void Capture_Destroy(ICapture *pCapture);

/**
 * 采集对象开始采集
 * @param pCapture 采集对象
 * @return true:调用成功
 */
bool Capture_Start(ICapture *pCapture);

/**
 * 采集对象停止采集
 * @param pCapture 采集对象
 */
void Capture_Stop(ICapture *pCapture);

#ifdef __cplusplus
}
#endif


#endif //FPLAYER_CAPTURE_H
